package mx.com.matersys.vacs.web;

import java.util.List;

import mx.com.matersys.vacs.domain.BitacoraRegistros;
import mx.com.matersys.vacs.domain.GenericResponse;
import mx.com.matersys.vacs.domain.TipoRegistro;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import flexjson.JSONSerializer;

@RooWebScaffold(path = "tiporegistroes", formBackingObject = TipoRegistro.class)
@RequestMapping("/tiporegistroes")
@Controller
public class TipoRegistroController {
	
	@RequestMapping(value = "/addTipoRegistro", method = RequestMethod.POST)
	public ResponseEntity<String> addPlanServicio(TipoRegistro tipoRegistro) {
		
		HttpHeaders headers;
		String json;
		GenericResponse gRes;
		ResponseEntity<String> response;
		
		headers = new HttpHeaders();
		headers.set("Content-Type", "application/json");
		headers.add("Content-Type", "application/text; charset=utf-8");
		
		System.out.println(tipoRegistro);
		
		tipoRegistro.persist();
		
		gRes = new GenericResponse(Boolean.TRUE, tipoRegistro);
		json = new JSONSerializer().exclude("*.class").serialize(gRes);
		
		response = new ResponseEntity<String>(json, headers, HttpStatus.OK);
		
		return response; 
	}
	
	@RequestMapping(value = "/readTipoRegistro", method = RequestMethod.GET)
	public ResponseEntity<String> readTipoRegistro(
			@RequestParam(value = "id", required = false) Integer idregistro) {
		
		HttpHeaders headers;
		String json;
		GenericResponse gRes;
		ResponseEntity<String> response;
		TipoRegistro tipoRegistro;
		
		headers = new HttpHeaders();
		headers.set("Content-Type", "application/json");
		headers.add("Content-Type", "application/text; charset=utf-8");
		
		tipoRegistro = TipoRegistro.findTipoRegistro(idregistro);
		
		gRes = new GenericResponse(Boolean.TRUE, tipoRegistro);
		json = new JSONSerializer().exclude("*.class").serialize(gRes);
		
		response = new ResponseEntity<String>(json, headers, HttpStatus.OK);
		
		return response; 
	}
	
	@RequestMapping(value = "/listTipoRegistro", method = RequestMethod.GET)
	public ResponseEntity<String> listTipoRegistro(){
		List<TipoRegistro> listB;
		HttpHeaders headers;
		
		headers = new HttpHeaders();
		headers.set("Content-Type", "application/json");
		headers.add("Content-Type", "application/text; charset=utf-8");
		
		listB = TipoRegistro.findAllTipoRegistroes();
		
		// generamos la respuesta exitosa, y agregamos la lista de estatus de planes de servicio
		GenericResponse gRes = new GenericResponse(Boolean.TRUE, listB);
		String json = new JSONSerializer().exclude("*.class").serialize(gRes);
		
		ResponseEntity<String> response = new ResponseEntity<String>(json, headers, HttpStatus.OK);
		return response;
	}
}
